﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using DrawableObjects.Actors.Aircrafts.Controller;

namespace InterfaceComponents
{
    /// <summary>
    /// This interface component is used for displaying text.
    /// </summary>
    public class Label : InterfaceComponent, HUDComponent
    {
	    private string text
	    {
		    get;
		    set;
	    }

	    private SpriteFont spriteFont;

	    public Label(string text, Vector2 position, SpriteBatch spriteBatch, SpriteFont spriteFont)
	    {
            this.text = text;
            this.position = position;
            this.spriteBatch = spriteBatch;
            this.spriteFont = spriteFont;
	    }

        /// <summary>
        /// Draws the Label with the specified color.
        /// </summary>
        /// <param name="color">Color of the font.</param>
        public override void Draw(Color color)
	    {
            spriteBatch.DrawString(spriteFont, text, position - new Vector2(2, 0), Color.Black);
            spriteBatch.DrawString(spriteFont, text, position + new Vector2(2, 0), Color.Black);
            spriteBatch.DrawString(spriteFont, text, position - new Vector2(0, 2), Color.Black);
            spriteBatch.DrawString(spriteFont, text, position + new Vector2(0, 2), Color.Black);
            spriteBatch.DrawString(spriteFont, text, position, color);
	    }

        /// <summary>
        /// SetValue is used by the HUDWrapper to update th component.
        /// </summary>
        public void SetValue(Object value)
        {
            if (value.GetType() == typeof(int))
            {
                text = ((int)value).ToString();
            }
            else if (value.GetType() == typeof(DroneMode))
            {
                text = (((DroneMode)value).modeID + 1).ToString();
            }
        }
    }
}

